<script lang="ts" setup>
import { reactive, ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { RouterEnums } from "@/types";
import { useI18n } from "vue-i18n";
import { ActivityAxios } from "@/api";
import { UserStore } from "@/store";
import { showSuccessToast, showToast, Progress } from "vant";
import { FiltrationFun } from "@/utils";
const userStore = UserStore();
const { t } = useI18n();
const router = useRouter();
// const keywords = reactive(['VIP vitalício', 'Bônus Gratuito', "retirado diretamente"]);
const texts = ref([] as any);

const vipList: any = reactive([]);

const gotoPage = () => {
  router.push(RouterEnums.VIPBONUSLIST);
};
onMounted(async () => {
  //活动配置
  await getconfig();
  getconfigDesc();
  if (userStore.isLogin) {
    await getVipInfo();
  }
});
const vipInfo: any = ref({
  allBet: 0,
  receiveType: 0,
  rewardPending: 0,
});
//进度条的值
const progressVal = ref(0);
//获取vip信息
const getVipInfo = async () => {
  await ActivityAxios.getVipInfo().then(res => {
    if (res) {
      vipInfo.value = res;
      vipList.map(item => {
        if (item.VipConfig.AllBet > vipInfo.value.allBet) {
          const progressPct = (vipInfo.value.allBet / 100 / (item.VipConfig.AllBet / 100)) * 100;
          progressVal.value = progressPct <= 100 ? progressPct : 100;
          return false;
        }
      });
      // progressVal.value=vipInfo.value.
    }
  });
};
//活动配置
const getconfig = async () => {
  await ActivityAxios.getconfig({ acttype: 1 }).then(res => {
    vipList.push(...res.configs);
    getNextLevelVIP();
  });
};
// 描述
const getconfigDesc = () => {
  ActivityAxios.getActConfigDesc({ actType: 1 }).then((res: any) => {
    texts.value = res.list;
  });
};
//获取奖励
const getReceiveVip = () => {
  if (userStore.isLogin) {
    if (vipInfo.value.receiveType !== 0) {
      ActivityAxios.getReceiveVip({ receivetype: vipInfo.value.receiveType }).then(res => {
        if (res === null) {
          showSuccessToast("successes");
          getVipInfo();
        }
      });
    } else {
      // PubSub.publish(PubSubEnum.SHOW_ERROR_TIP, {
      //   text: "没有任何可以领取的奖励",
      // });
      showToast({
        message: t("activity.actVIP.noRewards"),
        icon: "close",
      });
    }
  }
};
//单位过滤器
function formatToMillion(num) {
  if (num < 1000000) {
    return num.toString(); // 如果小于 1,000,000，直接返回原数字
  }
  return (num / 1000000).toFixed(2) + "M"; // 转换为百万单位并保留两位小数
}
const getNextLevel = ref({
  vipLevel: 0,
  allBet: 0,
});
//判断是否有下一级vip等级
const getNextLevelVIP: any = () => {
  const userVipLeve = userStore.userInfoDetails.account.vipLevel;
  vipList.map(item => {
    if (item.VipConfig.VipLevel > userVipLeve) {
      getNextLevel.value = {
        vipLevel: item.VipConfig.VipLevel,
        allBet: item.VipConfig.AllBet,
      };
    } else {
      getNextLevel.value = {
        vipLevel: userVipLeve,
        allBet: vipInfo.value.allBet,
      };
    }
  });
};
</script>
<template>
  <!-- VIP活动页面 -->
  <div class="frame-div">
    <div class="content-frame">
      <div class="content-div">
        <img class="vipv2-top-bg" src="@/image/new_img/activity/vip_top_bg.png" />
        <div class="interval-frame"></div>
        <div class="vip-val-frame df jc-space-between">
          <div class="vip-val">{{ userStore.userInfoDetails.account.vipLevel }}</div>
        </div>
        <div class="card-frame">
          <div class="card-content">
            <!-- <img class="vipv2-middle-frame" src="@/image/new_img/activity/vipv2_middle_bg.png" /> -->
            <img class="vipv2-middle-frame" src="@/image/new_img/activity/rebate_item_bg2.png" />
            <div class="card-text">
              <div class="card-text-top df jc-space-between">
                <div class="left-frame">
                  <div class="left-frame-title">{{ t("activity.actVIP.canReceive") }}</div>
                  <div class="left-frame-val">{{ vipInfo.rewardPending / 100 }}</div>
                </div>
                <div class="right-frame">
                  <div
                    class="right-frame-content"
                    :class="{ 'add-right-frame-content': vipInfo.rewardPending / 100 > 0 }"
                    @click="getReceiveVip"
                  >
                    {{ t("activity.actVIP.receber") }}
                  </div>
                </div>
              </div>
              <!-- 进度条 -->
              <div class="vip-vipframe-curvip">
                <div class="line-text-start-frame">
                  <div class="line-text-frame df jc-space-between">
                    <div class="left-text">{{ t("activity.actVIP.accumulatedBets") }}:</div>
                    <div class="left-text-frame df">
                      {{ FiltrationFun.formatNumber(vipInfo.allBet / 100) }}
                    </div>
                  </div>
                  <div class="progress-frame">
                    <div
                      class="progress-div"
                      :style="{
                        left: `calc(${progressVal}% - ${progressVal === 0 ? 0 : 8}px)`,
                      }"
                    ></div>
                    <Progress
                      :percentage="progressVal"
                      track-color="#ffffff26"
                      color="linear-gradient(90deg, #AB3FE7 0%, #FE7919 100%)"
                      stroke-width="0.2rem"
                      :show-pivot="false"
                    />
                  </div>
                  <div class="bottom-frame df ai-center jc-space-between">
                    <div class="left-text">0</div>
                    <div class="right-text">
                      {{ getNextLevel.allBet / 100 }}<span>(VIP {{ getNextLevel.vipLevel }})</span>
                    </div>
                  </div>
                </div>
              </div>
              <div class="card-text-bottom-frame df ai-center jc-space-between" @click="gotoPage">
                <div class="card-text-bottom df ai-center jc-space-between">
                  <div class="bottom-text">
                    {{ t("activity.actVIP.recordList") }}
                  </div>
                  <img class="vipv2-arrow" src="@/image/new_img/activity/vipv2_arrow.png" />
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- 分割线 -->
        <div class="divider-frame df ai-center jc-center">
          <div class="divider-div"></div>
          <div class="divider-name">{{ t("activity.eventDescription") }}</div>
          <div class="divider-div divider-div-rigth"></div>
        </div>
        <!-- 说明 -->
        <div class="highlight-frame">
          <!-- <Highlight :keywords="keywords" :source-string="text"/> -->
          <div v-for="(items, index) in texts" :key="index" class="textWrap">
            {{ `${index + 1}.${items?.actDescContent}` }}
          </div>
        </div>
        <!-- 列表 -->
        <div class="list-frame">
          <div class="list-title-frame df">
            <div class="text-tilte df ai-center text-tilte1">
              {{ t("activity.relief.level") }}
            </div>
            <div class="text-tilte df ai-center text-tilte1">
              {{ t("activity.subordinateList.bets") }}
            </div>
            <div class="text-tilte df ai-center">{{ t("activity.actVIP.upgradePrize") }}</div>
            <div class="text-tilte df ai-center">{{ t("activity.actVIP.weeklyBonus") }}</div>
            <div class="text-tilte df ai-center">{{ t("activity.actVIP.monthlyBonus") }}</div>
          </div>
          <div class="list-constent">
            <div v-for="(item, index) in vipList" :key="index" class="vipList-frame df ai-center">
              <div class="public-frame public-frame1 df ai-center jc-center">
                VIP{{ item.VipConfig.VipLevel }}
              </div>
              <div class="public-frame public-frame2 df ai-center jc-center">
                {{
                  item.VipConfig.AllBet / 100 < 1000000
                    ? FiltrationFun.formatNumber(item.VipConfig.AllBet / 100)
                    : formatToMillion(item.VipConfig.AllBet / 100)
                }}
              </div>
              <div class="public-frame public-frame3 df ai-center jc-center">
                {{ item.VipConfig.UpRewards / 100 }}
              </div>
              <div class="public-frame public-frame4 df ai-center jc-center">
                {{ item.VipConfig.WeekRewards / 100 }}
              </div>
              <div class="public-frame public-frame5 df ai-center jc-center">
                {{ item.VipConfig.MoonRewards / 100 }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="less" scoped>
.content-frame {
  width: 100%;
  height: 100%;
  position: relative;
  top: 0;
  left: 0;

  .content-div {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    position: absolute;
    top: 0px;
    left: 0;
    z-index: 2;
  }

  .content-div::-webkit-scrollbar {
    display: none;
  }
  .interval-frame {
    height: 180px;
  }
  .vipv2-top-bg {
    width: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
  }

  .vip-val-frame {
    width: 100%;
    height: 86px;
    text-align: center;
    margin: auto;

    .left-frame {
      width: 252px;
      height: 100%;
      position: relative;
      top: 0;
      left: 0;

      .vipv2-topleft-bg {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        z-index: -1;
      }

      .vipv2-topleft-text {
        width: 114px;
        height: 64px;
        margin-left: 31px;
      }
    }

    .vip-val {
      color: #ffd4b0;
      text-shadow: 5px 5px 4px #610097;
      text-align: center;
      font-size: 67px;
      margin: auto;
    }

    .vipv2-topleft-bg-img {
      transform: scaleX(-1);
    }

    .accumulationVal-frame {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      right: 19px;
      z-index: 1;
    }

    .valueNum {
      font-weight: 700;
      color: rgb(255, 212, 176);
      text-align: right;
      font-size: 34px;
      margin-top: 16px;
    }

    .title-frame {
      text-align: right;
      color: rgb(255, 212, 176);
      text-shadow: rgb(97 0 151) 5px 5px 4px;
      font-size: 16px;
      margin-top: 10px;
    }
  }

  .card-frame {
    width: 675px;
    height: 352.469px;
    margin: auto;
    margin-top: 101px;

    .card-content {
      width: 100%;
      height: 100%;
      position: relative;
      top: 0;
      left: 0;

      .vipv2-middle-frame {
        position: absolute;
        width: 100%;
        height: auto;
        object-fit: cover;
        top: 0;
        left: 0;
        z-index: 1;
      }

      .card-text {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 2;

        .left-frame-title {
          text-align: left;
          color: #f9c486;
          font-size: 27px;
          margin-left: 44px;
          margin-top: 50px;
        }

        .left-frame-val {
          color: rgb(244, 211, 157);
          text-align: left;
          font-weight: 700;
          font-size: 54px;
          margin-left: 44px;
          margin-top: 20px;
        }

        .right-content {
          width: 208.547px;
          height: 125px;
          background-image: url("../../image/new_img/activity/vipv2_btn_disable.png");
          background-size: 100% 100%;

          .receber-frame {
            width: 170.6px;
            height: 88px;
            color: rgba(255, 255, 255, 0.25);
            font-size: 23px;
            font-weight: 700;
            text-align: center;
            margin-left: auto;
          }
        }
        .card-text-bottom-frame {
          width: 100%;
          height: auto;
          margin-top: 30px;
        }
        .card-text-bottom {
          width: 100%;
          height: auto;
          color: #f9c486;
          .bottom-text {
            margin-left: 44px;
            font-size: 22px;
            font-weight: 700;
            color: #bb9367;
          }

          .vipv2-arrow {
            width: 26px;
            height: 26px;
            margin-right: 44px;
          }
        }
      }
    }
  }

  .divider-frame {
    width: 100%;
    height: auto;
    margin-top: 66px;

    .divider-div {
      width: 30%;
      height: 2px;
      background-image: linear-gradient(
        90deg,
        rgba(249, 196, 134, 0) 0%,
        rgba(249, 196, 134, 0.5) 100%
      );
    }

    .divider-div-rigth {
      transform: scaleX(-1);
    }

    .divider-name {
      color: #f9c486;
      font-size: 28px;
      margin-left: 13px;
      margin-right: 13px;
    }
  }

  .highlight-frame {
    width: 675px;
    height: auto;
    margin: auto;
    margin-top: 34px;
    color: rgba(249, 196, 134, 0.5);
    font-size: 26px;
    line-height: 40px;
    .textWrap {
      margin: 0 20px 0;
      word-wrap: break-word;
      margin-bottom: 30px;
    }
  }

  .list-frame {
    width: 675px;
    height: auto;
    margin: auto;
    margin-top: 66px;
  }

  .list-title-frame {
    width: 100%;
    height: 82px;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
    background: rgb(45 29 53);

    .text-tilte {
      flex: 1;
      font-size: 22px;
      color: rgba(255, 255, 255, 0.45);
      word-wrap: break-word;
      text-align: center;
      height: 82px;
      background: rgba(255, 255, 255, 0.08);
      line-height: 25px;
    }

    .text-tilte1 {
      width: 113px;
      display: flex;
      justify-content: center;
    }
  }

  .list-constent {
    width: 100%;
    height: auto;
    background: rgb(45 29 53);
    margin-bottom: 40px;
    .vipList-frame {
      width: 100%;
      text-align: center;
      height: 82px;
      line-height: 82px;
      font-size: 21px;
      border-bottom: 1px solid #1b0a24;
      color: rgba(255, 255, 255, 0.45);
    }

    .public-frame1 {
      width: 142px;
      color: rgba(255, 181, 127, 0.65);
      font-size: 26px;
    }

    .public-frame2 {
      width: 113px;
      font-size: 26px;
    }

    .public-frame3 {
      flex: 1;
      font-size: 26px;
    }

    .public-frame4 {
      flex: 1;
      font-size: 26px;
    }
    .public-frame5 {
      flex: 1;
      font-size: 26px;
    }
  }
}
.right-frame-content {
  width: 200px;
  height: 88px;
  border: 1px solid #594c4c;
  color: rgba(255, 255, 255, 0.25);
  font-size: 28px;
  border-radius: 30px;
  margin-top: 50px;
  margin-right: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border: 4px solid #f0d7bf;
}
.add-right-frame-content {
  color: #000000;
  background-image: linear-gradient(to right, #f3c28a, #d78545);
}
.vip-vipframe-curvip {
  width: calc(100% - 88px);
  height: 100px;
  margin: auto;
}
.line-text-start-frame {
  width: 600px;
  height: auto;
  margin: auto;
  .line-text-frame {
    width: 100%;
    height: 26px;
    padding-top: 16px;
    margin-bottom: 10px;
    .left-text {
      color: #ffffff73;
      font-size: 24px;
    }
    .color919 {
      color: #fe7919;
    }
    .nextReturn {
      margin-right: 6px;
      opacity: 0.5;
    }
  }
}
.bottom-frame {
  width: 600px;
  margin-top: 10px;
  .right-text {
    color: #00ffff;
    font-size: 22px;
  }
  .left-text {
    color: #736e73;
    font-size: 22px;
  }
}
.left-text-frame {
  color: #ffffffd9;
  font-size: 32px;
}
.progress-frame {
  position: relative;
  left: 0;
  top: 0;
  width: 100%;
  height: 16px;
  overflow-x: hidden;
  .progress-div {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #ffffff;
    position: absolute;
    top: 0;
    left: 0;
    transition: left 0.3s ease;
    z-index: 10;
  }
}
</style>
